package cn.bqjr.eily.samples.common.jackson.jsonserialize;

import cn.bqjr.eily.core.annotation.TransferKV;
import cn.bqjr.eily.core.serializer.JsonFieldSerializer;
import cn.bqjr.eily.samples.service.base.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * JSON KV字段序列化 TransferKV.KvType.DICT
 * Created by shan.he on 2017/7/11.
 */
@Component
public class DictFieldSerializer implements JsonFieldSerializer {

    @Autowired
    private IDictService dictService;

    @Override
    public boolean accept(TransferKV anno) {
        if (null != anno) {
            return TransferKV.KvType.DICT == anno.kvType();
        }
        return false;
    }

    @Override
    public String doSerialize(TransferKV anno, String str) {
        return dictService.queryDictVal(anno.codeType(), str);
    }
}
